package com.example.a2306_shop.adapter

import android.widget.Button
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ToastUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.a2306_shop.R
import com.example.lib_base.entity.Order
import com.example.lib_base.entity.OrderInfo
import com.example.user.GlideUtils

class OrderAdapter:BaseQuickAdapter<Order,BaseViewHolder>(R.layout.item_order) {
    override fun convert(holder: BaseViewHolder, item: Order) {
        holder.setText(R.id.order_time,item.createTime)
        holder.setText(R.id.order_status,item.orderStatus)
        holder.setText(R.id.order_total,"共${item.orderInfoList.size}种商品，合计金额:￥${item.payPrice}")
        //rv数据展示
        val opAdapter = OPAdapter()
        opAdapter.data.addAll(item.orderInfoList)
        val rv = holder.getView<RecyclerView>(R.id.order_rv)
        rv.adapter = opAdapter
        rv.layoutManager = LinearLayoutManager(context)

        //每种订单的按钮是不相同的
        if(item.orderStatus=="待支付"){
            holder.getView<Button>(R.id.order_btn1).text = "去付款"
        }else if(item.orderStatus=="待发货"){
            holder.getView<Button>(R.id.order_btn1).text = "催商家发货"
        }else{
            holder.getView<Button>(R.id.order_btn1).text = "功能项"
        }
    }
}
class OPAdapter:BaseQuickAdapter<OrderInfo,BaseViewHolder>(R.layout.item_order_product){
    override fun convert(holder: BaseViewHolder, item: OrderInfo) {
        GlideUtils.loadCorner(context,item.image,holder.getView(R.id.op_image),10)
        holder.setText(R.id.op_name,item.storeName)
        holder.setText(R.id.op_price,"￥${item.price}")
        holder.setText(R.id.op_num,"X${item.cartNum}")
        //点击 item  吐司商品名称
        holder.itemView.setOnClickListener {
            ToastUtils.showLong("点击的订单是${item.storeName}")
        }
    }

}